<? $url = $_SERVER['REQUEST_URI']; ?>

<div class="navbar navbar-fixed-top navbar-default">
  <div class="navbar-inner">
    <div class="container">
      <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="brand" href="/"><?= PROJECT_NAME ?></a>
      <div class="nav-collapse collapse">
        <ul class="nav">

		  <? if (!$this->user): ?>
            <li <?= ($url == "/")?'class="active"':'' ?>><a href="/">Home</a></li>
		  <? endif; ?>
		  <? if ($this->user->type == "admin"): ?>
		    <li><a href="/browse/all">Shop</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Manage <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="/manage/add-voucher-code">Add Cards</a></li>
              <li><a href="/manage/stats">Stats</a></li>
			  <li class="divider"></li>
              <li><a href="/manage/users">Users</a></li>
			</ul>
		  </li>
		  <li><a href="/account/refer">Refer to a friend</a></li>
		  <? elseif ($this->user->type == "user"): ?>
		  <li><a href="/browse/all">Shop</a></li>
		  <li><a href="/account/refer">Refer to a friend</a></li>
          <li class="dropdown" style="display:none">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Show Cards <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="/browse/simple">Simple style</a></li>
              <li><a href="/browse/pintrest">Image view</a></li>
			</ul>
		  </li>
		  <? else: ?>
            <li <?= ($url == "/account/login")?'class="active"':'' ?>><a href="/account/login">Login</a></li>
		  <? endif; ?>
        </ul>
		<? if ($this->user): ?>
<?
  $userName = $this->user->email;

  if ($this->user->type == "user")
    $userName = substr($this->user->email, 0, strpos($this->user->email, "@"));
?>
		<ul class="nav pull-right">
			<li><a href="#"><span id="nav-balance"><?= number_format( $this->user->bulk_credit, 2 ) ?> </span> <i id="nav-usd-sign" class="glyphicon-usd"></i></a></li>
		  <li><a href="/cart/browse"><span id="nav-cart-items-count"><?= count( $this->cart->getItems() )?> </span> <i id="nav-cart-icon" class="icon-shopping-cart icon-black"></i></a></li>
		  <li><a href="/messages/inbox"><?= $this->unreadMsgCount ?> <i class="icon-envelope icon-black"></i></a></li>
		  <li class="dropdown">
		    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-wrench icon-black"></i> <?= $userName ?> <b class="caret"></b></a>
		    <ul class="dropdown-menu">
		      <li><a href="/cart/browse"><i class="icon-shopping-cart"></i> View basket</a></li>
			  <li class="divider"></li>
		      <li><a href="/vouchers/purchases"><i class="icon-download"></i> My purchases</a></li>
		      <li><a href="/cart/bulk-credit"><i class="icon-download"></i> Deposit</a></li>
			  <li class="divider"></li>
		      <li><a href="/messages/inbox"><i class="icon-envelope"></i> View inbox</a></li>
		      <li><a href="/account/profile"><i class="icon-user"></i> Edit profile</a></li>
			  <li class="divider"></li>
		      <li><a href="/saved-vouchers/browse"><i class="icon-star"></i> Saved Cards</a></li>
			  <li class="divider"></li>
		  	  <li><a href="/account/logout"><i class="icon-off"></i> Logout</a></li>
		    </ul>
		  </li>
        </ul>
		<? endif; ?>
      </div><!--/.nav-collapse -->
    </div>
  </div>
</div>
